package com.ztsoft.user.controller.project;

import com.ztsoft.user.pojo.entity.project.SecondBargain;
import com.ztsoft.user.pojo.entity.project.SecondBargainApprove;
import com.ztsoft.user.service.project.SecondBargainApproveService;
import com.ztsoft.user.service.project.SecondBargainService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@CrossOrigin("*")
@RestController
@RequestMapping("/secondBargain")
@Api(tags = "代理机构控制层")
public class SecondBargainController {
    @Resource
    private SecondBargainService secondBargainService;
    @Resource
    private SecondBargainApproveService approveService;

    @PutMapping("/update")
    @ApiOperation(value = "修改二次议价", notes = "修改二次议价")
    public Result<Object> updateSecondBargain(@RequestBody SecondBargain project) {
        return secondBargainService.updateSecondBargain(project);
    }

    @PutMapping("/sendApprove/{id}")
    @ApiOperation(value = "提交审核二次议价", notes = "提交审核二次议价")
    public Result<Object> approveSecondBargain(@PathVariable("id") String id) {
        return secondBargainService.approve(id);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加二次议价", notes = "添加二次议价")
    public Result<Object> addSecondBargain(@RequestBody SecondBargain project) {
        return secondBargainService.addSecondBargain(project);
    }

    @PutMapping("/received/{id}")
    @ApiOperation(value = "已收服务费", notes = "已收服务费")
    public Result<Object> receivedSecondBargain(@PathVariable("id") String id) {
        return secondBargainService.received(id);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除二次议价", notes = "删除二次议价")
    public Result<Object> deleteSecondBargain(@PathVariable("id") String id) {
        return secondBargainService.deleteSecondBargain(id);
    }

    //查询二次议价列表
    @GetMapping("/querySecondBargain/{projectId}/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查询项目关联的二次报价单", notes = "根据关联关系查询项目关联的二次报价单")
    public Result<Object> querySecondBargain(@PathVariable("projectId") String projectId,
                                                 @PathVariable("currentPage") Integer currentPage,
                                                 @PathVariable("pageSize") Integer pageSize) {
        return secondBargainService.querySecondBargain(projectId, "0", currentPage, pageSize);
    }

    //查询二次议价列表
    @GetMapping("/querySecondBargainApprove/{projectId}/{status}/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查询项目关联的二次报价单", notes = "根据关联关系查询项目关联的二次报价单")
    public Result<Object> querySecondBargainApprove(@PathVariable("projectId") String projectId,
                                             @PathVariable("status") String status,
                                             @PathVariable("currentPage") Integer currentPage,
                                             @PathVariable("pageSize") Integer pageSize) {
        return secondBargainService.querySecondBargain(projectId, status, currentPage, pageSize);
    }

    //查询二次议价列表
    @GetMapping("/querySecondBargainApproved/{projectId}/{pageSize}/{currentPage}")
    @ApiOperation(value = "根据关联关系查询项目关联的二次报价单", notes = "根据关联关系查询项目关联的二次报价单")
    public Result<Object> querySecondBargainApproved(@PathVariable("projectId") String projectId,
                                                    @PathVariable("currentPage") Integer currentPage,
                                                    @PathVariable("pageSize") Integer pageSize) {
        return secondBargainService.querySecondBargain(projectId, "5,6,7,8,9", currentPage, pageSize);
    }

    @PutMapping("/approve/update")
    @ApiOperation(value = "修改二次议价审核", notes = "修改二次议价审核")
    public Result<Object> updateSecondBargainApprove(@RequestBody SecondBargainApprove project) {
        return approveService.updateSecondBargainApprove(project);
    }

    @PostMapping("/approve/add")
    @ApiOperation(value = "添加二次议价审核", notes = "添加二次议价审核")
    public Result<Object> addSecondBargainApprove(@RequestBody SecondBargainApprove project) {
        return approveService.addSecondBargainApprove(project);
    }

    @DeleteMapping("/approve/delete/{id}")
    @ApiOperation(value = "删除二次议价审核", notes = "删除二次议价审核")
    public Result<Object> deleteSecondBargainApprove(@PathVariable("id") String id) {
        return approveService.deleteSecondBargainApprove(id);
    }

    /**
     * 计算缴费费用并保存
     */
    @PutMapping("/calculateCharge/{chargeType}/{id}")
    @ApiOperation(value = "计算缴费费用并保存", notes = "计算缴费费用并保存")
    public Result<Object> calculateCharge(@PathVariable("chargeType") String chargeType, @PathVariable("id") String id) {
        return secondBargainService.calculateCharge(chargeType, id);
    }

}
